<?php 
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
MYDCONN();
$GLOBALS['MYT']=$GLOBALS['MYD'];
form_pr('getContracts','','','post'); ?>
<div class="title">Contractos</div>
<table width="98%"  border="0" cellpadding="3" cellspacing="1">
  <?php
  if (!isset($_GET['Iv'])) { 
  
  echo '<tr bgcolor="#F2F2F2">
  	<td width="5%">Numero</td>
    <td width="25%">Descricao</td>
    <td width="25%">Fornecedor</td>
    <td width="5%">Conta</td>
    <td width="5%">NIB</td>
    <td width="5%">Tipo</td>
    <td width="5%">Estado</td>
  </tr>';

	$Results = $GLOBALS['MYD']->db_array("SELECT 
					ccenter_contractos.Ref,
					ccenter_contractos.Description,
					ccenter_contractos.CODE,
					ccenter_contractos.NIB,
					ccenter_contractos.Type,
					hcce_status.name AS Status,
					ccenter_providers.name AS Provider
				FROM ccenter_contractos 
				INNER JOIN ccenter_providers ON ccenter_providers.Ref = ccenter_contractos.RefProvider
				INNER JOIN hcce_status ON hcce_status.StatRef = ccenter_contractos.Status AND hcce_status.Type = 2
				ORDER BY ccenter_contractos.Ref ASC"); 
	for ($f = 1; $f <= $Results[0]; $f++) { 
	
		echo'<tr height="20" bgcolor="'.gridlines($f).'">
		<td>'; mn_field('button','ED','ccptID',$Results[$f]['Ref'],'','','','" style="width:60px;" onclick="
			idwindow(\'Propriedades do contracto\',\'ccwinc\',\'ccwinct\',\'Modules/CentrodeCustos/Lib/frm_contract.php?ccptID='.$Results[$f]['Ref'].'\',300,300);'); echo '</td>
		<td>'.$Results[$f]['Description'].'</td>
		<td>'.$Results[$f]['Provider'].'</td>
		<td>'.$Results[$f]['CODE'].'</td>
		<td>'.$Results[$f]['NIB'].'</td>
		<td>'.$Results[$f]['Type'].'</td>
		<td>'.$Results[$f]['Status'].'</td>
		</tr>';
   }  
   } else {
	echo '<tr bgcolor="#D3D6E4">
		<td colspan="5">^ Listagem de Contratos Minimizada | <a href="?jB=4">Maximizar (+)</a></td>
		</tr>';
  }?>
</table>
<?php 
 if (isset($_GET['Iv'])) { ?>
<br>
<table width="100%"  border="0" cellspacing="1" cellpadding="3">
<form action="?jB=<?php echo $_GET['jB'];?>&Iv=<?php echo $_GET['Iv'];?>" method="post" name="EditContract" runat="server">
  <?php
   $Results = $GLOBALS['CONN']->db_array("SELECT 
					Contr.Ref,
					Contr.Description,
					Contr.CODE,
					Contr.NIB,
					ccenter_contas.name AS CodeName,
					Contr.Client,
					Contr.Type,
					Contr.Status,
					ccenter_providers.name AS Provider
				FROM ccenter_contractos AS Contr
				INNER JOIN ccenter_providers ON ccenter_providers.Ref = Contr.RefProvider
				INNER JOIN ccenter_contas ON ccenter_contas.CODE = Contr.CODE
				WHERE Contr.Ref = {$_GET['Iv']}"); 
	for ($f = 1; $f <= $Results[0]; $f++) { 
	echo '<input value="'.$Results[$f]['Ref'].'" name="Contract" type="hidden" id="Contract">';
	?>

  <tr bgcolor="#ACB1CC">
    <td colspan="5">Propriedades do Contrato </td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td width="21%">Descrição:</td>
    <td colspan="4"><input value="<?php echo $Results[$f]['Description']?>" name="name" type="text" id="name" size="70"></td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td>Cliente:</td>
    <td><input  value="<?php echo $Results[$f]['Client']?>" name="Client" type="text" id="Client" size="24" maxlength="255"></td>
    <td>Tipo:
      <select name="TYPE" id="select">
        <option value="2">Externo</option>
        <option value="1">Interno</option>
      </select></td>
    <td colspan="2">Estado:
      <select name="Status" id="Status">
        <?php
	  $List = $GLOBALS['MYD']->db_array("SELECT StatRef,name
	  			FROM hcce_status
				WHERE Type = 2");
		for($r = 1; $r <= $List[0]; $r++) {
		echo '<option value="'.$List[$r]['StatRef'].'"';
		if ($List[$r]['StatRef'] == $Results[$f]['Status']) { print 'selected';}
		echo '>'.$List[$r]['name'].'</option>';
		}
		?>
      </select></td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td>NIB: </td>
    <td width="33%"><input value="<?php echo $Results[$f]['NIB']?>" name="NIB" type="text" id="NIB" size="22" maxlength="21"></td>
    <td width="20%">&nbsp;</td>
    <td colspan="2">&nbsp;</td>
  </tr>
  <tr bgcolor="#FBFBFB">
    <td colspan="5">&nbsp;</td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td colspan="5">Area</td>
  </tr>
  <tr bgcolor="#FBFBFB">
    <td>CÓdigo</td>
    <td colspan="4">Descrição</td>
  </tr>
	<tr bgcolor="#FBFBFB">
    <td><?php echo $Results[$f]['CODE'];?></td>
    <td colspan="4"><?php echo $Results[$f]['CodeName'];?></td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td>&nbsp;</td>
    <td colspan="4">Fornecedor</td>
  </tr>
  <tr bgcolor="#FBFBFB">
    <td>&nbsp;</td>
    <td><b><?php echo $Results[$f]['Provider'];?></b></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td>&nbsp;</td>
    <td colspan="4"><input name="EditContract" type="submit" id="EditContract" value="Salvar AlteraÇ&otilde;es"></td>
  </tr>
  <?php } ?>
  </form>
</table>
<?php } ?>